import { MigrationInterface, QueryRunner } from "typeorm";

export class CreateUserToken1705239666763 implements MigrationInterface {
    name = 'CreateUserToken1705239666763'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`
            CREATE TABLE \`user_token\` (
                \`user_id\` int NOT NULL COMMENT '用户id',
                \`token\` varchar(100) NOT NULL,
                \`status\` tinyint NOT NULL COMMENT '状态[1:有效, 0:无效]' DEFAULT '1',
                \`datetime\` datetime NOT NULL COMMENT '到期时间',
                \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
                \`updated_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
                PRIMARY KEY (\`user_id\`, \`token\`)
            ) ENGINE = InnoDB
        `);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`
            DROP TABLE \`user_token\`
        `);
    }

}
